﻿Imports DotNetNuke.Web.Services
Imports System.Web
Imports System.Web.Mvc
Imports DotNetNuke.Common
Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Entities.Content.Common
Imports DotNetNuke.Entities.Host
Imports DotNetNuke.Entities.Users
Imports DotNetNuke.Security
Imports DotNetNuke.Services.Localization
Imports DotNetNuke.Services.Social.Notifications
Imports DotNetNuke.Services.Journal
Imports DotNetNuke.Services.FileSystem
Imports System.Globalization


Namespace DotNetNuke.Modules.ActiveForums
    <ValidateAntiForgeryToken()> _
    Public Class ForumServiceController
        Inherits DnnController
        <DnnAuthorize()> _
        Public Function CreateThumbnail(FileId As Integer, Height As Integer, Width As Integer) As ActionResult

            Dim _fileManager As IFileManager = FileManager.Instance()
            Dim _folderManager As IFolderManager = FolderManager.Instance()

            Dim _file As IFileInfo = _fileManager.GetFile(FileId)

            If _file Is Nothing Then
                Return Json(New With {.Result = "error"})
            End If
            Dim _folder As IFolderInfo = _folderManager.GetFolder(_file.FolderId)

            Dim ext As String = _file.Extension
            If Not ext.StartsWith(".") Then
                ext = "." + ext
            End If
            Dim sizedPhoto As String = _file.FileName.Replace(ext, "_" + Width.ToString(CultureInfo.InvariantCulture) + "x" + Height.ToString(CultureInfo.InvariantCulture) + ext)
            
            Dim newPhoto As IFileInfo = _fileManager.AddFile(_folder, sizedPhoto, _fileManager.GetFileContent(_file))
            sizedPhoto = ImageUtils.CreateImage(newPhoto.PhysicalPath, Height, Width)
            newPhoto = _fileManager.UpdateFile(newPhoto)

            Return Json(newPhoto)

        End Function
        <DnnAuthorize()> _
        Public Function EncryptTicket(Url As String) As String
            Return UrlUtils.EncryptParameter(UrlUtils.GetParameterValue(Url))
        End Function

    End Class
End Namespace
